#include <stdio.h>
#include <stdlib.h>

#define  N  10

//快速排序法
int quick_sort(int *a, int low, int high)
{
    int l=low;
    int r=high;
    int key=a[low];

    while (l<r) {
        while (l<r && a[r]>=key) {
            r--;
        }
        a[l]=a[r];
        while (l<r&&a[l]<=key) {
            l++;
        }
        a[r]=a[l];
    }
    a[l]=key;
    if (l-1>low) {
        quick_sort(a,low,l-1);
    }
    if (l+1<high) {
        quick_sort(a,l+1,high);
    }
    return 0;
}

//程序的入口
int main(int argc, const char *argv[])
{
    //先整了个数组，初始化了一堆数，一共十个，N 宏定义了 10
    int a[N] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 0};

    int i = 0;
    printf("排序之前:\n");
    for(i = 0; i < N; i++)
    {
        printf("%d ", a[i]);
    }
    putchar('\n');//==换行printf("\n");

    //调用-快排
    quick_sort(a, 0, N-1);//数组，0 ，9

    printf("排序之后:\n");
    for(i = 0; i < N; i++)
    {
        printf("%d ", a[i]);
    }
    putchar('\n');//==换行==printf("\n");

    return 0;
}